home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Trazados, regiones y recorte / WidenPath / WidenPath.cs next >
Encoding:
Text File  |  2002-05-06  |  2.0 KB  |  63 lines

  1. //----------------------------------------
  2. // WidenPath.cs ⌐ 2001 by Charles Petzold
  3. //----------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8.  
  9. class WidenPath: PrintableForm
  10. {
  11.      GraphicsPath path;
  12.  
  13.      public new static void Main()
  14.      {
  15.           Application.Run(new WidenPath());
  16.      }
  17.      public WidenPath()
  18.      {
  19.           Text = "Trazado ensanchado";
  20.  
  21.           path = new GraphicsPath();
  22.  
  23.                // Crear subtrazado abierto.
  24.  
  25.           path.AddLines(new Point[] { new Point(20, 10),
  26.                                       new Point(50, 50),
  27.                                       new Point(80, 10) });
  28.  
  29.                // Crear subtrazado cerrado.
  30.  
  31.           path.AddPolygon(new Point[] { new Point(20, 30),
  32.                                         new Point(50, 70),
  33.                                         new Point(80, 30) });
  34.      }
  35.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  36.      {
  37.           grfx.ScaleTransform(cx / 300f, cy / 200f);
  38.  
  39.           for (int i = 0; i < 6; i++)
  40.           {
  41.                GraphicsPath pathClone = (GraphicsPath) path.Clone();
  42.                Matrix       matrix    = new Matrix();
  43.                Pen          penThin   = new Pen(clr, 1);
  44.                Pen          penThick  = new Pen(clr, 5);
  45.                Pen          penWiden  = new Pen(clr, 7.5f);
  46.                Brush        brush     = new SolidBrush(clr);               
  47.  
  48.                matrix.Translate((i % 3) * 100, (i / 3) * 100);
  49.  
  50.                if (i < 3)
  51.                     pathClone.Transform(matrix);
  52.                else
  53.                     pathClone.Widen(penWiden, matrix);
  54.  
  55.                switch (i % 3)
  56.                {
  57.                case 0:  grfx.DrawPath(penThin, pathClone);   break;
  58.                case 1:  grfx.DrawPath(penThick, pathClone);  break;
  59.                case 2:  grfx.FillPath(brush, pathClone);     break;
  60.                }
  61.           }
  62.      }
  63. }